package com.videomaru
{
	import flash.events.Event;
	
	/*********************************************************************************************************
	* This custom Event class is used to communicate between the player and the media, as well as from the
	* Player and further on. 
	* 
	* @example <p>To listen for these events, make sure you import the class and set up a listener that can respond
	* to the event. To do something when the Player is ready to display the duration of the loaded file, you can
	* do like this:</p>
	* <code><pre>import com.videomaru.PlayerEvent;
	* function myFunction(e:PlayerEvent):void {
	*     trace("The loaded file has a duration of "+myPlayer.duration+" seconds");
	* }
	* myPlayer.addEventListener(PlayerEvent.METADATA,myFunction);</pre></code>
	* <p>This will import the library, define a function to execute when the event occurs and set up 
	* a listener on your Player instance:</p>
	* 
	* <p>PS: As always with Actionscript 3, make sure you remove this listener as well using this command:</p>
	* <code>myPlayer.removeEventListener(PlayerEvent.METADATA,myFunction);</code>
	* <p>Failure to do so, may prevent the Flash Player from unloading the video from memory. That in turn can cause video playing while it should not</p>
	*********************************************************************************************************/
	
	public class MaruEvent extends Event
	{
		public static const VOLUME_CHANGE:String   = "onVolumeChange";
		public static const METADATA:String = "onMetaData";
		// public static const CUEPOINT:String = "onCuePoint"; // Not yet implemented
		public static const COMPLETE:String = "onComplete";
		public static const ASPECT:String   = "onAspect";
		public static const START:String   = "onStart";
		public static const PAUSE:String   = "onPause";
		public static const STOP:String   = "onStop";
		public static const SEEK:String   = "onSeek";
		public static const INIT:String   = "onInit";
		public static const MUTE:String   = "onMute";
		public static const UNMUTE:String   = "onUnmute";
		public static const BUFFER_FULL:String   = "onBufferFull";
		
		public static const SECURITY_ERROR:String   = "onSecurityError";
		public static const IO_ERROR:String   = "onIOError";
		
		public static const PLAY_PROGRESS:String   = "onPlayProgress";
		public static const BUFFER_PROGRESS:String   = "onBufferProgress";
		public static const DOWNLOAD_PROGRESS:String   = "onDownloadProgress";
		
		/**
		*  CHANGED
		*  Broadcast when the state changes
		*/
		public static const CHANGED:String = "Changed";
		
		/**
		 * A text message that can be passed to an event handler with this event object.
		 */
		public var message:String;
		
		/**
		 * A value that can be passed to an event handler, usually contains the value described in "message".
		 */
		public var value:Number;
		
		public function MaruEvent(type:String, bubbles:Boolean = false,cancelable:Boolean = false, msg:String = null,val:Number = undefined)
		{
			//Log.dbg("MaruEvent "+arguments);
			message = msg;
			value = val;
			super(type, bubbles, cancelable);
		}
		
		/**
		 * Creates and returns a copy of the current instance.
		 * @return A copy of the current instance.
		 */
		public override function clone():Event
		{
			Log.dbg("MaruEvent cloned "+arguments);
			return new MaruEvent(type, bubbles, cancelable);
		}
		/**
		 * Returns a String containing all the properties of the current
		 * instance.
		 * @return A string representation of the current instance.
		 */
		public override function toString():String
		{
			Log.dbg("toString MaruEvent "+arguments);
			return formatToString("MaruEvent","type","bubbles","cancelable","eventPhase","message","value");
		}
	}
}